from typing import Optional

from fastapi import Query

from app.core.base_response import BaseResponse
from app.service import category_service
from app.validator.model import CategoryItem, CategoryUpdate


async def create_category(model:CategoryItem):
    await category_service.create(model)
    return BaseResponse.success()

async def del_category(_id: Optional[str] = Query(None, min_length=3, max_length=50)):
    await category_service.delete_category(_id)
    return BaseResponse.success()

async def update_category(*, _id: Optional[str] = Query(None, min_length=3, max_length=50),
                        model: CategoryUpdate):
    await category_service.update(_id, model)
    return BaseResponse.success()

async def get_category(_id: Optional[str] = Query(None, min_length=3, max_length=50)):
    data = await category_service.read(_id)
    return BaseResponse.success(data=data)

async def get_category_list():
    data = await category_service.read_list()
    return BaseResponse.success(data=data)